package newsEventSystem;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class NewsCenter {

	private static NewsCenter instance = null;
	private static ArrayList<Domain> listOfDomains = new ArrayList<Domain>();

	private NewsCenter() {
		readDomains();
	}

	public static NewsCenter getInsance() {
		if (instance == null) {
			instance = new NewsCenter();
		}
		return instance;
	}

	public List<Domain> getDomains() {
		return listOfDomains;
	}

	private void readDomains() {
		try {
			FileInputStream fis = new FileInputStream("Domains.txt");
			BufferedReader br = new BufferedReader(new InputStreamReader(fis));
			String line;
			while ((line = br.readLine()) != null) {
				listOfDomains.add(new Domain(line, null));
			}
			br.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	public void addDomain(Domain d){
		listOfDomains.add(d);
	}
	
	public void addNews(News aNews){
			for(Domain d : listOfDomains)
				if(d.getDomainName().equals(aNews.getDomainName()))
					d.addNewsToDomain(aNews);
		
	}
}
